package com.chauncy.DMS.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.chauncy.DMS.dao.ManagerDaoImplement;

public class GetWeiGuiInfoServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ManagerDaoImplement daoImplement = new ManagerDaoImplement();
			String sql = "SELECT Count(stu_att_info_table.No_return) AS `data`, " +
			 "stu_dorm_info_table.Dormitory_number AS `name`" +
			 " FROM stu_att_info_table , " +
			 "stu_dorm_info_table " +
			 "WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= DATE(Att_date) " +
			 "AND stu_att_info_table.No_return > 0 " +
			 "AND stu_att_info_table.Stu_number = stu_dorm_info_table.Stu_number " +
			 "GROUP BY stu_dorm_info_table.Dormitory_number;";
			List<Map<String, Object>> qingjiaCountList =  daoImplement.query(sql);
			if(qingjiaCountList != null && qingjiaCountList.size() > 0){
				JSONArray array = JSONArray.fromObject(qingjiaCountList);
				System.out.println(array);
				response.getWriter().print(array);
			}
	}

}
